package com.symaster.backups.frame.page.configs;

import com.symaster.backups.frame.MainFrame;
import com.symaster.backups.frame.element.scrollbar.Scrollbar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.util.List;

/**
 * @author yinmiao
 * @version 2024/2/5
 */
@Component
public class Config extends MainFrame.Item {

    private final List<ConfigItem> configItems;

    @Autowired(required = false)
    public Config(List<ConfigItem> configItems) {
        this.configItems = configItems;
        Scrollbar scrollbar = new Scrollbar();

        JPanel jPanel = new JPanel();
        jPanel.setLayout(new FlowLayout(FlowLayout.LEADING, 5, 5));
        scrollbar.setContentPane(jPanel);
        setLayout(new BorderLayout());
        add(scrollbar);

        if (configItems != null) {
            for (ConfigItem configItem : configItems) {
                configItem.setBorder(new TitledBorder(configItem.label()));
                jPanel.add(configItem);
            }
        }
    }

    @Override
    public String label() {
        return "系统配置";
    }

    @Override
    public void viewEvent() {
        for (ConfigItem configItem : configItems) {
            configItem.viewEvent();
        }
    }
}
